package cn.itcast.service.impl;

import cn.itcast.domain.Room;
import cn.itcast.mapper.RoomMapper;
import cn.itcast.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper mapper;

    /**
     * 查询所有房间
     * @return
     * 返回房间信息
     */
    @Override
    public List<Room> findAll(HttpServletRequest request) {
        List<Room> rooms = mapper.findAll();
        request.getSession().setAttribute("rooms",rooms);
        return rooms;

    }

/**
 *  管理员新增房间
 */
    @Override
    public void addRoom(Room room) {
        mapper.addRoom(room);
    }

    /**
     * 删除房间
     * @param id
     * 根据id删除房间
     */
    @Override
    public void deleRoom(int id) {
        mapper.deleRoom(id);
    }

    /**
     * 根据房间id修改房间状态
     */
    @Override
    public void updateRoom(Room room){
        mapper.update(room);
    }
}
